import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { MemberConst } from "src/consts/member_const";
import { PopupName } from "src/consts/popup_const";
@Component({})
export default class MemberAddPanel extends MyVue {
    name: string = 'MemberAddPanel';
    formData: any;
    footerFlag: boolean = true;
    feature_code: any;

    initData(that?: any): void {
        that.formData = WLStore().state.memberShow;
        that.feature_code = Config.featureCode + 'common.entity.Role'
    }

    mounted(): void {
    }

    created(): void {
        for (let key in WLStore().state.memberShow) {
            WLStore().state.memberShow[key] = null
            if (key == "status") {
                WLStore().state.memberShow[key] = "qiyong"
            }
        }
    }


    loopAdd(list: any[], arr: any[]): void {
        if (isNoEmpty(list)) {
            for (let i = 0; i < list.length; i++) {
                arr.push(list[i].id)
                if (isNoEmpty(list[i].child_list)) {
                    this.loopAdd(list[i].child_list, arr)
                }
            }
        }
    }

    addAcc(): void {
        this.$refs.memberAddForm.validate((valid: Boolean) => {
            if (valid) {
                let sendData: any = this.formData
                sendData.isContinue = false
                var arr = ["ROLE_assist_start",
                "ROLE_assist_operate_request",
                "ROLE_assist_webhistory_add",
                "ROLE_assist_webaccount_get",
                "ROLE_assist_task_close",
                "ROLE_assist_config_get",
                "ROLE_assist_operate_result_get",
                "ROLE_assist_camsgpin_get",
                "ROLE_assist_website_get",
                "ROLE_assist_cookie_get",
                "ROLE_option_list"]

                if (isNoEmpty(this.formData.Authority)) {
                    for (let i = 0; i < this.formData.Authority.length; i++) {
                        arr.push(this.formData.Authority[i].id)
                    }
                }

                sendData.authority_list = arr
                delete sendData.feature_code
                delete sendData.Authority
                delete sendData.formData
                delete sendData.id
                WLDispatch(MemberConst.DispatchMemberAdd, sendData);
            } else {
                WLMessage("必填字段为空,无法新增角色", "warning")
                return false;
            }
        })
    }

    continueAddAcc(): void {
        this.$refs.memberAddForm.validate((valid: Boolean) => {
            if (valid) {
                let sendData: any = this.formData
                sendData.isContinue = true
                var arr = ["ROLE_assist_start",
                "ROLE_assist_operate_request",
                "ROLE_assist_webhistory_add",
                "ROLE_assist_webaccount_get",
                "ROLE_assist_task_close",
                "ROLE_assist_config_get",
                "ROLE_assist_operate_result_get",
                "ROLE_assist_camsgpin_get",
                "ROLE_assist_website_get",
                "ROLE_assist_cookie_get",
                "ROLE_option_list"]
                for (let i = 0; i < this.formData.Authority.length; i++) {
                    arr.push(this.formData.Authority[i].id)
                }

                // var list = WLStore().state.memberSet.allData
                // for (let i = 0; i < list.length; i++) {
                //     if (list[i].id == "ROLE_Lv1fuzhuxitong" || list[i].id == "ROLE_Lv1qita") {
                //         for (let k = 0; k < list[i].child_list.length; k++) {
                //             this.loopAdd(list[i].child_list[k].child_list, arr)
                //         }
                //     }
                // }

                sendData.authority_list = arr
                delete sendData.feature_code
                delete sendData.Authority
                delete sendData.formData
                delete sendData.id
                WLDispatch(MemberConst.DispatchMemberAdd, sendData);
            } else {
                WLMessage("必填字段为空,无法新增角色", "warning")
                return false;
            }
        })

        setTimeout(() => {
            for (let key in WLStore().state.memberShow) {
                WLStore().state.memberShow[key] = null
            }
        }, 500);
    }

    authority(): void {
        WLCommit(MemberConst.CommitType, "add")
        let senData: any = {}
        WLDispatch(MemberConst.DispatchMemberSet, senData);
    }

}